<?php
/**
 * 教室信息类
 */
namespace app\admin\controller;

use think\App;
use think\facade\View;
use app\admin\model\Signmodel;
use app\admin\validate\Student as validate;

class Sign extends Common
{
    protected $cfmodel;

    public function __construct(App $app)
    {
        $this->validate = validate::class;
        $this->validateType = 'student';
        $this->localModel = new Signmodel();
        parent::__construct($app);
    }

    public function index()
    {
        $dataArr = $this->request->request('search/a', []);

        if($dataArr['nickname'])  $where[] = ['s.nickname', 'like', "%".$dataArr['nickname']."%"];
        if($dataArr['username'])  $where[] = ['s.username', 'like', "%".$dataArr['username']."%"];
        if($dataArr['start_time'])  $where[] = ['sg.create_date', '>=', $dataArr['start_time']];
        if($dataArr['end_time'])  $where[]   = ['sg.create_date', '<=', $dataArr['end_time']];

        $list = $this->localModel->getAllStudentSign($where, $this->request->param());
        $showDataArr = ['data'=>$list['data'], 'pageData'=>$list['page'], 'dataArr'=>$dataArr, 'page'=>$this->request->get('page')];
        View::assign(array_merge($dataArr, $showDataArr));
        return view();
    }

    public function add(){
        $id = $this->request->get('id', 0);

        if($id){
            $showData['id'] = $id;
            $showData['detail'] = $this->localModel->getDetailStudentSignById($id);
            View::assign($showData);
            return view('edit');
        }else{
            return view();
        }
    }

}
